package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.business.BusinessDTO;
import com.qk.dto.business.BusinessFollowDTO;
import com.qk.dto.business.BusinessHighSeasDTO;
import com.qk.dto.business.BusinessQueryDTO;
import com.qk.entity.Business;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.BusinessService;
import com.qk.vo.business.BusinessQueryVO;
import com.qk.vo.business.BusinessVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author lyl
 * @created 2025/10/15 11:34
 * @description
 *
 */
@Slf4j
@RestController
@RequestMapping("/businesses")
@SuppressWarnings("all")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @GetMapping
    public Result getListByPage(BusinessQueryDTO businessQueryDTO) {
        log.info("分页查询商机,参数:商机id={},客户名称={},,客户手机号={},商机状态={},归属人={},所属员工姓名={},当前页码={},每页大小={}",businessQueryDTO.getBusinessId(), businessQueryDTO.getName(),businessQueryDTO.getPhone(), businessQueryDTO.getStatus(), businessQueryDTO.getAssignName(), businessQueryDTO.getPage(), businessQueryDTO.getPageSize());
        PageResult<BusinessQueryVO> pageResult = businessService.getListByPage(businessQueryDTO);
        return Result.success(pageResult);
    }
    @LogAnno
    @PostMapping
    public Result addBusiness(@RequestBody BusinessDTO businessDTO) {
        log.info("添加商机：businessDTO={}", businessDTO.toString());
        businessService.addBusiness(businessDTO);
        return Result.success();
    }
    @LogAnno
    @PutMapping("/assign/{businessId}/{userId}")
    public Result assignBusiness(@PathVariable Integer businessId, @PathVariable Integer userId) {
        log.info("分配商机：businessId={},userId={}", businessId, userId);
        businessService.assignBusiness(businessId, userId);
        return Result.success();
    }
    @LogAnno
    @PutMapping("/back/{id}")
    public Result backHighSeas(@PathVariable Integer id) {
        log.info("踢回公海：id={}", id);
        businessService.backHighSeas(id);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getBusinessById(@PathVariable Integer id) {
        log.info("根据ID查询商机详情：id={}", id);
        BusinessVO businessVO = businessService.getBusinessById(id);
        return Result.success(businessVO);
    }
    @LogAnno
    @PutMapping
    public Result followBusiness(@RequestBody BusinessFollowDTO businessFollowDTO) {
        log.info("跟进商机：businessDTO={}", businessFollowDTO.toString());
        businessService.followBusiness(businessFollowDTO);
        return Result.success();
    }
    @GetMapping("/pool")
    public Result getHighSeasList(BusinessHighSeasDTO businessHighSeasDTO) {
        log.info("查询公海商机");
        PageResult<Business> list = businessService.getHighSeasList(businessHighSeasDTO);
        return Result.success(list);
    }
}
